<?
$limit = 20;
$count = fgsMatchs::getCount();
$start = $count - $limit;
if (fgsBase::isParam(0))
	$start = (int)fgsBase::getParam(0);
$matchs = fgsMatchs::getLast($limit, $start);
$previous = $start - $limit;
if ($previous < 1)
	$previous = 1;
$next = $start + $limit;
if ($next > $count - $limit)
	$next = $count - $limit;
?>
<h2><?=tr('Matchs')?></h2>
<div class="toolbar">
<? 
	if ($start != $previous) {
		echo fgsBase::linkPage('&laquo; previous', 'matchs', array($previous));
		echo ' | ';
	}
	printf(tr('%d/%d matchs'), $start, $count);
	if ($start != $next) {
		echo ' | ';
		echo fgsBase::linkPage('next &raquo;', 'matchs', array($next));
	}
?>
</div>
<?

	$table = new htmlTable();
	$table->setHeader('game', array(
		'width' => '16px',
	));
	$table->setHeader('id', array(
		'title' => '#',
		'width' => '7ex',
	));
	$table->setHeader('date', array(
		'title' => tr('Started'),
	));
	$table->setHeader('duration', array(
		'title' => tr('Duration'),
		'width' => '12ex',
	));
	$table->setHeader('status', array(
		'title' => tr('Status'),
		'width' => '10ex',
	));
	$table->setHeader('count', array(
		'title' => tr('Nb'),
		'width' => '3ex',
	));

	if (is_array($matchs)) {

		foreach ($matchs as $k=>$match) {
			
			if ($match['match_status_ret'] == -1) 
				$table->setLineParam('class', 'disabled'); 

			$table->set('id', fgsBase::linkPage('#'.$k, 'match', array($k)));
			$table->set('date', fgsUtils::formatDate($match['match_datecreate']));
			$table->set('duration', fgsUtils::formatSeconds($match['match_duration']));
			$table->set('status', $match['match_status']);
			$table->set('count', $match['nb_players']);

			$table->set('game', fgsBase::linkPage(
				sprintf('<img src="%s" alt="%s"/>', fgsBase::link('game', array($match['game_gid'], 'logo', 'icon16')), $match['game_name']),
				'game', array($match['game_gid'])
			));

			$table->push();
		}
		
		echo $table->render();
	} else {
		echo tr('No matchs yet.');
	}

?>
